package main

import "fmt"

func main() {

	//第一种方式
	var a map[string]string
	//在使用map前，需要先make，make的作用就是给map分配数据空间
	a = make(map[string]string, 10)
	a["no1"] = "宋江"
	a["no2"] = "卢俊义"
	fmt.Println(a)

	//第二种方式  直接make
	cities := make(map[string]string)
	cities["no1"] = "北京"
	cities["no2"] = "上海"
	cities["no3"] = "天津"
	fmt.Println(cities)

	//第三种方式 声明直接赋值
	//heroes := map[string]string{
	//	"hero1": "钢铁侠",
	//	"hero2": "蜘蛛侠",
	//}
	//上下两种都行
	var heroes map[string]string = map[string]string{
		"hero1": "钢铁侠",
		"hero2": "蜘蛛侠",
	}
	heroes["hero3"] = "绿巨人"
	fmt.Println(heroes)

	//案例
	/*
		课堂练习：演示一个key-value 的value是map的案例
		比如：我们要存放3个学生信息, 每个学生有 name和sex 信息
		思路:   map[string]map[string]string

	*/
	studentMap := make(map[string]map[string]string)

	studentMap["stu01"] = make(map[string]string, 3)
	studentMap["stu01"]["name"] = "tom"
	studentMap["stu01"]["sex"] = "男"
	studentMap["stu01"]["address"] = "北京长安街~"

	studentMap["stu02"] = make(map[string]string, 3) //这句话不能少!!
	studentMap["stu02"]["name"] = "mary"
	studentMap["stu02"]["sex"] = "女"
	studentMap["stu02"]["address"] = "上海黄浦江~"

	fmt.Println(studentMap)
	fmt.Println(studentMap["stu02"])
}
